package com.youuvs.basic.service.impl;

import com.youuvs.basic.mapper.BaseMapper;
import com.youuvs.basic.query.BaseQuery;
import com.youuvs.basic.service.IBaseService;
import com.youuvs.basic.utils.PageList;
import com.youuvs.org.domian.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;
    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    @Override
    public T findById(Long id) {
        return (T) baseMapper.findById(id);
    }


    @Override
    public void delete(Long id) {
        baseMapper.delete(id);

    }

    @Override
    public void insert(T t) {
        baseMapper.insert(t);

    }

    @Override
    public void update(T t) {
        baseMapper.update(t);

    }

    @Override
    public PageList<T> queryPage(BaseQuery query) {
        //查询到总条数
        Integer count = baseMapper.queryCount(query);
        //根据总条数
        if(count<1){
            return new PageList<>();
        }else{
            List<T> list = baseMapper.queryData(query);
            return new PageList<T>(count,list);
        }

    }

    @Override
    public void patchDel(List<Long> ids) {
        baseMapper.patchDel(ids);

    }
}
